package com.nanhai.buddhist.college.module.study.controller.admin.attendancemanagementlog;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

import com.nanhai.buddhist.college.framework.excel.core.util.ExcelUtils;

import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import static com.nanhai.buddhist.college.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.nanhai.buddhist.college.module.study.controller.admin.attendancemanagementlog.vo.*;
import com.nanhai.buddhist.college.module.study.dal.dataobject.attendancemanagementlog.AttendanceManagementLogDO;
import com.nanhai.buddhist.college.module.study.convert.attendancemanagementlog.AttendanceManagementLogConvert;
import com.nanhai.buddhist.college.module.study.service.attendancemanagementlog.AttendanceManagementLogService;

@Api(tags = "管理后台 - 请假审核记录")
@RestController
@RequestMapping("/study/attendance-management-log")
@Validated
public class AttendanceManagementLogController {

    @Resource
    private AttendanceManagementLogService attendanceManagementLogService;

    @PostMapping("/create")
    @ApiOperation("创建请假审核记录")
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:create')")
    public CommonResult<String> createAttendanceManagementLog(@Valid @RequestBody AttendanceManagementLogCreateReqVO createReqVO) {
        return success(attendanceManagementLogService.createAttendanceManagementLog(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新请假审核记录")
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:update')")
    public CommonResult<Boolean> updateAttendanceManagementLog(@Valid @RequestBody AttendanceManagementLogUpdateReqVO updateReqVO) {
        attendanceManagementLogService.updateAttendanceManagementLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除请假审核记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:delete')")
    public CommonResult<Boolean> deleteAttendanceManagementLog(@RequestParam("id") String id) {
        attendanceManagementLogService.deleteAttendanceManagementLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得请假审核记录")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:query')")
    public CommonResult<AttendanceManagementLogRespVO> getAttendanceManagementLog(@RequestParam("id") String id) {
        AttendanceManagementLogDO attendanceManagementLog = attendanceManagementLogService.getAttendanceManagementLog(id);
        return success(AttendanceManagementLogConvert.INSTANCE.convert(attendanceManagementLog));
    }

    @GetMapping("/list")
    @ApiOperation("获得请假审核记录列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:query')")
    public CommonResult<List<AttendanceManagementLogRespVO>> getAttendanceManagementLogList(@RequestParam("ids") Collection<String> ids) {
        List<AttendanceManagementLogDO> list = attendanceManagementLogService.getAttendanceManagementLogList(ids);
        return success(AttendanceManagementLogConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得请假审核记录分页")
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:query')")
    public CommonResult<PageResult<AttendanceManagementLogRespVO>> getAttendanceManagementLogPage(@Valid AttendanceManagementLogPageReqVO pageVO) {
        PageResult<ManagementLogResVO> pageResult = attendanceManagementLogService.getAttendanceManagementLogPage(pageVO);
        return success(AttendanceManagementLogConvert.INSTANCE.convertManagementLogResVOPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出请假审核记录 Excel")
    @PreAuthorize("@ss.hasPermission('study:attendance-management-log:export')")
    @OperateLog(type = EXPORT)
    public void exportAttendanceManagementLogExcel(@Valid AttendanceManagementLogExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<AttendanceManagementLogDO> list = attendanceManagementLogService.getAttendanceManagementLogList(exportReqVO);
        // 导出 Excel
        List<AttendanceManagementLogExcelVO> datas = AttendanceManagementLogConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "请假审核记录.xls", "数据", AttendanceManagementLogExcelVO.class, datas);
    }

}
